package {{packageName}}.server.test.common

import com.firefly.core.ApplicationContext
import com.firefly.kotlin.ext.context.Context
import com.firefly.kotlin.ext.context.getBean
import com.firefly.kotlin.ext.db.asyncUpdate
import {{packageName}}.server.dao.db.DbClient
import kotlinx.coroutines.runBlocking

/**
 * @author Pengtao Qiu
 */
object Context {

    val ctx: ApplicationContext = Context.create()

    fun init() = runBlocking {
        val dbClient: DbClient = ctx.getBean()
        dbClient.getDbClient().execSQL {
            it.asyncUpdate("DROP SCHEMA IF EXISTS firefly_seed")
            it.asyncUpdate("CREATE SCHEMA IF NOT EXISTS firefly_seed")
            it.asyncUpdate("set mode MySQL")
            it.asyncUpdate(
                """
                CREATE TABLE IF NOT EXISTS `firefly_seed`.`firefly_kt_web_seed_project`(
                    id BIGINT AUTO_INCREMENT PRIMARY KEY,
                    create_time DATETIME NOT NULL,
                    update_time DATETIME NOT NULL,
                    name VARCHAR(45) NOT NULL
                )
            """.trimIndent()
                          )
        }
    }

}